package com.manage.competition.service.impl;

import com.manage.competition.entity.Contact;
import com.manage.competition.mapper.ContactMapper;
import com.manage.competition.repository.ContactRepository;
import com.manage.competition.service.IContactService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 15:06 2019/3/31
 * @Description:
 */
@Service
public class ContactServiceImpl implements IContactService {

    @Autowired
    private ContactMapper contactMapper;

    @Autowired
    private ContactRepository contactRepository;

    @Override
    public int insert(Contact contact) {
        contact.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        contact.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return contactMapper.insert(contact);
    }

    @Override
    public int update(Contact contact) {
        contact.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return contactMapper.updateByPrimaryKeySelective(contact);
    }

    @Override
    public Contact getById(long id) {
        return contactRepository.findById(id).orElse(null);
    }

    @Override
    public int deleteByPrimaryKey(Long contactId) {
        return contactMapper.deleteByPrimaryKey(contactId);
    }
}
